package wiki.generic.iotests;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.HashMap;

import wiki.generic.io.MapDataReader;
import wiki.generic.utilities.Substring;
/**
 * 
 * @author <p><strong>JwTeam</strong></p> 
 *
 */
public class ConcreteDataMapReader implements MapDataReader {

	private String filePath;
	
	public ConcreteDataMapReader(String filePath) {
		
		this.filePath=filePath;
		
	}
	
	
	@Override
	public String getFile() {
		
		return filePath;
	}
	
@Override
	public HashMap<String, String> getMap() {
	
	File file = new File(filePath);
	HashMap<String, String> map = new HashMap<String, String>();
	
	try {
		BufferedReader reader = new BufferedReader(new FileReader(file));
		String s = reader.readLine();
		while (s != null) {
			putInMap(s, map);
			s = reader.readLine();
		}
	} catch (FileNotFoundException e) {
		e.printStackTrace();
	} catch (IOException e) {
		e.printStackTrace();
	}
		return map;
	}
	


	private void putInMap(String line, HashMap<String, String> map){
		
		Substring sub=new Substring(line, "$$||$$");
		String chiave = sub.nextSubString();
		String valore= sub.nextSubString();
		
		map.put(chiave, valore);
		
		
	}
}
